package com.example.web_project_xianyu.mappers;

import com.example.web_project_xianyu.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface productMapper {
    @Select("select * from product_table")
    List<Product> select_all_product();

    @Select("select * from product_table where product_class = #{product_class}")
    List<Product> select_product_bytype(int product_class);

    @Select("select * from product_table where product_id = #{product_id}")
    Product select_product_by_id(int product_id);

    @Select("select * from product_table where user_id = #{user_id}")
    List<Product> select_product_by_user_id(int user_id);

    @Insert("insert into product_table(`product_name` , `user_id` , `product_class` , `product_describe` " +
            ", `time` , `like` , `comment_number` , `picture` , `store` , `price` ) " +
            "values( #{productName}, #{userId}, #{productClass}, #{productDescribe}, #{time} , #{like} , " +
            " #{commentNumber} , #{picture} , #{store} , #{price})")
    @Options(useGeneratedKeys = true,keyProperty = "productId")
    void add_product(Product product);

    @Delete("delete from product_table where product_id=#{product_id}")
    void delete_product(int product_id);

    @Update("update product_table set  `LIKE` = `LIKE` + 1 where product_id = #{product_id}")
    void like_add(int product_id);

    @Update("update product_table set `LIKE` = `LIKE` - 1 where product_id = #{product_id}")
    void like_remove(int product_id);

    @Update("update product_table set  `COMMENT_NUMBER` = `COMMENT_NUMBER` + 1 where product_id = #{product_id}")
    void commentNumber_add(int product_id);

}
